package com.zhouyu.service;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Locale;

@Component
public class UserServiceNew implements ApplicationContextAware {

	@Autowired
	private OrderService orderService;

	private ApplicationContext context;

	public UserServiceNew() {
		System.out.println("constructor");
	}


	@Override
	public void setApplicationContext(ApplicationContext context) throws BeansException {
		this.context = context;
	}


	@PostConstruct
	public void postCon() {
		System.out.println("post construct");
	}

	// @Transactional(rollbackFor = Exception.class)
	public void test() {
		System.out.println(context.getMessage("name", null, Locale.getDefault()));
		System.out.println(orderService);
	}


	// @Transactional(rollbackFor = Exception.class)
	public void transA() {
		transB();        // 不会开启新事务
		this.transB();  // 不会开启新事务

		orderService.transB(); // 会开启新事务，因为有了新的代理
	}


	// @Transactional(rollbackFor = Exception.class, propagation = Propagation.NEVER)
	public void transB() {

	}
}